<template>
  <el-dialog
    :title="'批量修改'"
    :close-on-click-modal="false"
    :visible.sync="visible"
		center
  >
	<el-button class="miui-dialog-close-btn" @click="visible = false">关闭页面</el-button>
    <el-form
      class="verify-form"
      :model="dataForm"
      :rules="dataRule"
      ref="dataForm"
      label-width="80px"
    >
      <el-form-item label="1元兑换积分比例" prop="exchangeRate">
        <el-input v-model="dataForm.exchangeRate" placeholder="1元兑换积分比例"></el-input>
      </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit" :loading="ischeck" v-prevent-re-click>确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
import { batchEditExchangeRate } from "@/api/eims/integralrule";

export default {
  data() {
    var exchangeRateCheck = (rule, value, callback) => {
      let numPattern = /^-?\d*\.?\d+$/
      if (!numPattern.test(value)) {
        callback(new Error("请输入纯数字"));
      }else{
        callback()
      }
    };
    return {
			ischeck: false,
      visible: false,
      isIndeterminate: false,
      checkAll: false,
      deptOptions: [],
      dataForm: {
        ids: [],
        exchangeRate: ""
      },
      dataRule: {
        exchangeRate: [
          { required: true, message: "1元兑换积分比例不能为空", trigger: "blur" },
          { validator: exchangeRateCheck}
        ]
      }
    };
  },

  methods: {
    init(ids) {
      this.dataForm.ids = ids
      this.visible = true;
      this.$nextTick(() => {
        this.$refs["dataForm"].resetFields();
      });
    },
    // 表单提交
    dataFormSubmit() {
			this.ischeck = true
      this.$refs["dataForm"].validate(valid => {
        if (valid) {
          batchEditExchangeRate(this.dataForm).then(response => {
						if(response.data.code == '0'){
							this.$message.success("修改成功")
							this.visible = false;
							this.$emit("refreshDataList")
						}else{
							this.$message.error(response.data.msg)
						}
						this.ischeck = false
          }).catch(() => {
            this.ischeck = false
          })
        }else{
					this.ischeck = false
				}
      });
    }
  }
};
</script>
